import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import 'home_page.dart';
import 'category_page.dart';
import 'Cart_page.dart';
import 'member_page.dart';
import 'package:Smart/pages/productor005/studytest/flutter_shop/provide/current_index_provide.dart';

import 'package:Smart/pages/productor005/studytest/flutter_shop/config/string.dart';



//索引页的底部导航栏
class IndexPage extends StatelessWidget {
  //底部按钮
  final List<BottomNavigationBarItem> bottomTabs = [
    BottomNavigationBarItem(
        icon: Icon(Icons.home),
      title: Text(KString.homeTitle),//首页
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.category),
      title: Text(KString.categoryTitle),//分类
    ),BottomNavigationBarItem(
      icon: Icon(Icons.shopping_cart),
      title: Text(KString.shoppingCartTitle),//购物车
    ),BottomNavigationBarItem(
      icon: Icon(Icons.person),
      title: Text(KString.memberTitle),//会员中心
    )
  ];
  //引入各个页面
  final List<Widget> tabBodies=[
    HomePage(),
    CategoryPage(),
    CartPage(),
    MemberPage()
  ];
  @override
  Widget build(BuildContext context) {
    //屏幕适配
    

    return Provide<CurrentIndexProvide>(
      builder: (context,child,val){
        //取到当前索引状态值
        int currentIndex=Provide.value<CurrentIndexProvide>(context).currentIndex;//状态值
        return Scaffold(
          backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
          bottomNavigationBar: BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            currentIndex: currentIndex,//当前默认索引值为0
            items: bottomTabs,//每个Bar的选项
            onTap: (index){
              Provide.value<CurrentIndexProvide>(context).changeIndex(index);
            },
          ),
          body: IndexedStack(
            index: currentIndex,
            children: tabBodies,
          ),
        );
      },
    );
  }

}